﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Styx.WoWInternals.DBC;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using Styx.Common;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.Pathing;
using Styx;
using System.Diagnostics;
using System.Threading;
using System.IO;
using Styx.CommonBot;
using System.Windows.Forms;
using Styx.CommonBot.Inventory;

namespace KingWoW
{
    class ArcaneMageCombatClass : KingWoWAbstractBaseClass
    {

        private static string Name = "KingWoW ArcaneMage'";

        #region CONSTANT AND VARIABLES

        //START OF CONSTANTS ==============================
        private const bool LOGGING = true;
        private const bool DEBUG = false;
        private const bool TRACE = false;
        private KingWoWUtility utils = null;
        private Movement movement = null;
        private ExtraUtils extra = null;

        private WoWUnit tank = null;
        private WoWUnit lastTank = null;
        private bool LazyRaiderBotType = true;
        private bool RaidBotBotType = false;
        private bool SoloBotType = false;
        private bool PVPBotType = false;
        private string BaseBot = "unknown";
        private DateTime nextTimeRuneOfPowerAllowed;

        private const string DEBUG_LABEL = "DEBUG";
        private const string TRACE_LABEL = "TRACE";
        private const string TANK_CHANGE = "TANK CHANGED";
        private const string FACING = "FACING";

        //START OF SPELLS AND AURAS ==============================
        private const string DRINK = "Drink";
        private const string FOOD = "Food";

        private const string FROSTFIRE_BOLT = "Frostfire Bolt";
        private const string FROST_NOVA = "Frost Nova";
        private const string FIRE_BLAST = "Fire Blast";
        private const string BLINK = "Blink";
        private const string COUNTERSPELL = "Counterspell";
        private const string SUMMON_WATER_ELEMENTAL = "Summon Water Elemental";
        private const string FROSTBOLT = "Frostbolt";
        private const string POLYMORPH = "Polymorph";
        private const string ARCANE_EXPLOSION = "Arcane Explosion";
        private const string ICE_LANCE = "Ice Lance";
        private const string FINGER_OF_FROST = "Fingers of Frost";
        private const string ICE_BLOCK = "Ice Block";
        private const string CONE_OF_COLD = "Cone of Cold";
        private const string REMOVE_CURSE = "Remove Curse";
        private const string SLOW_FALL = "Slow Fall";
        private const string MOLTEN_ARMOR = "Molten Armor";
        private const string ICY_VEINS = "Icy Veins";
        private const string CONJURE_REFRESHMENT = "Conjure Refreshment";
        private const string EVOCATION = "Evocation";
        private const string FLAMESTRIKE = "Flamestrike";
        private const string CONJURE_MANA_GEM = "Conjure Mana Gem";
        private const string MIRROR_IMAGE = "Mirror Image";
        private const string BLIZZARD = "Blizzard";
        private const string FROST_ARMOR = "Frost Armor";
        private const string INVISIBILITY = "Invisibility";
        private const string ARCANE_BRILLANCE = "Arcane Brilliance";
        private const string FROZEN_ORB = "Frozen Orb";
        private const string SPELLSTEAL = "Spellsteal";
        private const string DEEP_FREEZE = "Deep Freeze";
        private const string CONJURE_REFRESHMENT_TABLE = "Conjure Refreshment Table";
        private const string BRAIN_FREEZE = "Brain Freeze";
        private const string MAGE_ARMOR = "Mage Armor";
        private const string TIME_WARP = "Time Warp";
        private const string ALTER_TIME = "Alter Time";

        private const string ARCANE_BARRAGE = "Arcane Barrage";
        private const string ARCANE_MISSILES = "Arcane Missiles";
        private const string ARCANE_MISSILES_PROC = "Arcane Missiles!";
        private const string ARCANE_BLAST = "Arcane Blast";
        private const string ARCANE_CHARGE = "Arcane Charge";
        private const string ARCANE_POWER = "Arcane Power";

        private const string BRILLIANT_MANA_GEM = "Brilliant Mana Gem";
        private const string MANA_GEM = "Brilliant Mana Gem";
        

        private const string FREEZE = "Freeze";
        //END OF SPELLS AND AURAS ==============================

        //TALENTS
        private const string PRESENCE_OF_MIND = "Presence of Mind";
        private const string SCORCH = "Scorch";
        private const string ICE_FLOES = "Ice Floes";
        private const string TEMPORAL_SHIELD = "Temporal Shield";
        private const string BLAZING_SPEED = "Blazing Speed";
        private const string ICE_BARRIER = "Ice Barrier";
        private const string RING_OF_FROST = "Ring of Frost";
        private const string ICE_WARD = "Ice Ward";
        private const string FROSTJAW = "Frostjaw";
        private const string GREATER_INVISIBILITY = "Greater Invisibility";

        private const string COLD_SNAP = "Cold Snap";
        private const string NETHER_TEMPEST = "Nether Tempest";
        private const string LIVING_BOMB = "Living Bomb";
        private const string FROST_BOMB = "Frost Bomb";
        private const string INVOCATION = "Invocation";
        private const string RUNE_OF_POWER = "Rune of Power";
        private const string INCANTER_WARD = "Incanter's Ward";
        //END TALENTS
        //END OF CONSTANTS ==============================

        #endregion

        public ArcaneMageCombatClass()
        {
            utils = new KingWoWUtility();
            movement = new Movement();
            extra = new ExtraUtils();
            tank = null;
            lastTank = null; ;
            LazyRaiderBotType = true;
            SoloBotType = false;
            PVPBotType = false;
            RaidBotBotType = false;
            BaseBot = "unknown";
            nextTimeRuneOfPowerAllowed = DateTime.Now;
        }

        public override bool Combat
        {
            get
            {
                extra.AnyKeyBindsPressed();
                if (ExtraUtilsSettings.Instance.PauseRotation || !StyxWoW.IsInGame || !StyxWoW.IsInWorld || /*utils.IsGlobalCooldown(true) ||*/ utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD) || Me.IsChanneling || utils.MeIsCastingWithLag())
                    return false;
                BotUpdate();

                //UPDATE TANK
                //tank = utils.GetTank();
                tank = utils.SimpleGetTank();
                if (tank == null || !tank.IsValid || !tank.IsAlive) tank = Me;

                if (lastTank == null || lastTank.Guid != tank.Guid)
                {
                    lastTank = tank;
                    utils.LogActivity(TANK_CHANGE, tank.Name);
                }
                return CombatRotation();
            }
        }

        public override bool Pulse
        {
            get
            {
                extra.AnyKeyBindsPressed();
                if (ExtraUtilsSettings.Instance.PauseRotation || !StyxWoW.IsInGame || !StyxWoW.IsInWorld || /*utils.IsGlobalCooldown(true) ||*/ utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD) || Me.IsChanneling || utils.MeIsCastingWithLag())
                    return false;
                BotUpdate();

                //UPDATE TANK
                //tank = utils.GetTank();
                tank = utils.SimpleGetTank();
                if (tank == null || !tank.IsValid || !tank.IsAlive) tank = Me;

                if (lastTank == null || lastTank.Guid != tank.Guid)
                {
                    lastTank = tank;
                    utils.LogActivity(TANK_CHANGE, tank.Name);
                }
                if (tank != null && tank.Combat && !Me.GotTarget)
                    return CombatRotation();
                return false; 
            }
        }

        public override bool Pull
        {
            get
            {
                WoWUnit target = Me.CurrentTarget;
                if (target != null && !target.IsFriendly && target.Attackable && !target.IsDead)
                {
                    if (!target.InLineOfSight || target.Distance > 40)
                    {
                        movement.KingHealMove(target.Location, ArcaneMageSettings.Instance.PullDistance, true, true);
                        return false;
                    }
                    if (utils.CanCast(ARCANE_BLAST) /*&& !Me.IsMoving*/)
                    {
                        if (!Me.IsMoving && !Me.IsFacing(target))
                        {
                            utils.LogActivity(FACING, target.Name);
                            Me.SetFacing(target);
                        }

                        utils.LogActivity(ARCANE_BLAST, target.Name);
                        return utils.Cast(ARCANE_BLAST, target);
                    }
                }
                return false;
            }
        }

        public override bool Initialize
        {
            get
            {
                utils.GoStopWatchUpdateTank();
                extra.GoStopWatchUpdateKeyBinds();
                if (ExtraUtilsSettings.Instance.SoundsEnabled)
                {
                    try
                    {
                        SoundManager.LoadSoundFilePath(@"\Routines\King-wow\Sounds\Welcome.wav");
                        SoundManager.SoundPlay();
                    }
                    catch { }
                }
                Logging.Write("Ciao " + Me.Name);
                Logging.Write("Welcome to " + Name + " custom class");
                Logging.Write("Tanks All HonorBuddy Forum developers for code inspiration!");
                Logging.Write("Powered by Attilio76");
                return true; ;
            }
        }

        public override bool NeedCombatBuffs { get { return Buff(); } }

        public override bool NeedPreCombatBuffs { get { return Buff(); } }

        public override bool NeedPullBuffs { get { return Buff(); } }

        public override bool NeedRest
        {
            get
            {
                if ((utils.isAuraActive(DRINK) || utils.isAuraActive(FOOD)) && (Me.ManaPercent < 100 || Me.HealthPercent < 100))
                    return true;
                if (Me.ManaPercent <= ArcaneMageSettings.Instance.ManaPercent &&
                !utils.isAuraActive(DRINK) && !Me.Combat && !Me.IsMoving && !utils.MeIsCastingWithLag())
                {
                    WoWItem mydrink = Consumable.GetBestDrink(false);
                    if (mydrink != null)
                    {
                        utils.LogActivity("Drinking/Eating");
                        Styx.CommonBot.Rest.DrinkImmediate();
                        return true;
                    }
                }
                if (Me.HealthPercent <= ArcaneMageSettings.Instance.HealthPercent &&
                !utils.isAuraActive(FOOD) && !Me.Combat && !Me.IsMoving && !utils.MeIsCastingWithLag())
                {
                    WoWItem myfood = Consumable.GetBestFood(false);
                    if (myfood != null)
                    {
                        utils.LogActivity("Eating");
                        Styx.CommonBot.Rest.DrinkImmediate();
                        return true;
                    }
                }
                return false;
            }
        }

        public void SetNextTimeRuneOfPower()
        {
            //3 seconds wait to avoid popping 2 rune of frost cause has high priority
            nextTimeRuneOfPowerAllowed = DateTime.Now + new TimeSpan(0, 0, 0, 0, 3000);
        }

        private bool PriorityBuff()
        {
            if (Me.Combat && utils.CanCast(INCANTER_WARD) && ArcaneMageSettings.Instance.UseIncenterWardOnCD)
            {
                utils.LogActivity(INCANTER_WARD);
                return utils.Cast(INCANTER_WARD);
            }

            if (!Me.IsMoving && nextTimeRuneOfPowerAllowed < DateTime.Now && ArcaneMageSettings.Instance.UseRuneOfPower && !utils.isAuraActive(RUNE_OF_POWER, Me) && Me.Combat && utils.CanCast(RUNE_OF_POWER))
            {
                utils.LogActivity(RUNE_OF_POWER);
                utils.Cast(RUNE_OF_POWER);
                SetNextTimeRuneOfPower();
                return SpellManager.ClickRemoteLocation(Me.Location);
            }
            return false;
        }

        private bool Buff()
        {
            if (utils.Mounted() || utils.MeIsCastingWithLag() || ExtraUtilsSettings.Instance.PauseRotation)
                return false;
            //Mana Gem
            if (!Me.Combat && !utils.HaveManaGem() && Me.Level >= 30 && utils.CanCast(CONJURE_MANA_GEM) && !Me.IsMoving)
            {
                utils.LogActivity(CONJURE_MANA_GEM);
                return utils.Cast(CONJURE_MANA_GEM);
            }

            //Armor
            switch (ArcaneMageSettings.Instance.ArmorToUse)
            {
                case ArcaneMageSettings.ArmorType.FROST:
                    if (!utils.isAuraActive(FROST_ARMOR) && utils.CanCast(FROST_ARMOR) && !Me.IsMoving)
                    {
                        utils.LogActivity(FROST_ARMOR);
                        return utils.Cast(FROST_ARMOR);
                    }
                    break;
                case ArcaneMageSettings.ArmorType.MOLTEN:
                    if (!utils.isAuraActive(MOLTEN_ARMOR) && utils.CanCast(MOLTEN_ARMOR) && !Me.IsMoving)
                    {
                        utils.LogActivity(MOLTEN_ARMOR);
                        return utils.Cast(MOLTEN_ARMOR);
                    }
                    break;
                case ArcaneMageSettings.ArmorType.MAGE:
                    if (!utils.isAuraActive(MAGE_ARMOR) && utils.CanCast(MAGE_ARMOR) && !Me.IsMoving)
                    {
                        utils.LogActivity(MAGE_ARMOR);
                        return utils.Cast(MAGE_ARMOR);
                    }
                    break;
            }

            //arcane brillance
            if (ArcaneMageSettings.Instance.AutoBuffBrillance && !utils.isAuraActive(ARCANE_BRILLANCE) && utils.CanCast(ARCANE_BRILLANCE))
            {
                utils.LogActivity(ARCANE_BRILLANCE);
                return utils.Cast(ARCANE_BRILLANCE);
            }

            if (ArcaneMageSettings.Instance.UseIcebarrier && Me.Combat && utils.CanCast(ICE_BARRIER) && !utils.isAuraActive(ICE_BARRIER))
            {
                utils.LogActivity(ICE_BARRIER);
                return utils.Cast(ICE_BARRIER);
            }

            if (Me.Combat && utils.CanCast(TEMPORAL_SHIELD))
            {
                utils.LogActivity(TEMPORAL_SHIELD);
                return utils.Cast(TEMPORAL_SHIELD);
            }


            if (Me.Combat && (tank != null && tank.Combat) && utils.CanCast(ICE_WARD) && ArcaneMageSettings.Instance.IceWardOnTank &&
                !utils.isAuraActive(ICE_WARD, tank) && tank != null && tank.IsAlive && tank.Distance < 40 &&
                tank.InLineOfSight)
            {
                utils.LogActivity(ICE_WARD, tank.Name);
                return utils.Cast(ICE_WARD, tank);
            }

            if (!Me.IsMoving && utils.isAuraActive(INVOCATION) && !StyxWoW.Me.ActiveAuras.ContainsKey(INVOCATION))
            {
                utils.LogActivity(EVOCATION);
                return utils.Cast(EVOCATION);
            }

            
            return false;
        }

        private bool ProcWork()
        {
            if (!utils.isAuraActive(ARCANE_POWER, Me) && utils.PlayerCountBuff(ARCANE_MISSILES_PROC) > 0 || utils.PlayerCountBuff(ARCANE_CHARGE) >= 6)
            {
                WoWUnit target = utils.getTargetToAttack(40, tank);
                if (target != null)
                { 
                    if (!Me.IsMoving)
                    {
                        Me.SetFacing(target);
                    }
                    if (utils.PlayerCountBuff(ARCANE_MISSILES_PROC) == 2 && !ArcaneMageSettings.Instance.MissilesOnlyAtMaxCharge
                        && utils.CanCast(ARCANE_MISSILES,target))
                    {
                        utils.LogActivity(ARCANE_MISSILES, target.Name);
                        return utils.Cast(ARCANE_MISSILES, target);
                    }
                    if (!utils.isAuraActive(ARCANE_POWER) && utils.PlayerCountBuff(ARCANE_CHARGE) == 6 && utils.CanCast(ARCANE_BARRAGE,target)
                        && !(utils.PlayerCountBuff(ARCANE_MISSILES_PROC) > 0) && 
                        (Me.ManaPercent <= ArcaneMageSettings.Instance.BarrageAtMana
                        || utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 20).Count() >= ArcaneMageSettings.Instance.AOECount))
                    {
                        utils.LogActivity(ARCANE_BARRAGE, target.Name);
                        return utils.Cast(ARCANE_BARRAGE, target);
                    }
                    if (utils.PlayerCountBuff(ARCANE_MISSILES_PROC) > 0 && utils.PlayerCountBuff(ARCANE_CHARGE) == 6
                        && utils.CanCast(ARCANE_MISSILES, target))
                    {
                        utils.LogActivity(ARCANE_MISSILES, target.Name);
                        return utils.Cast(ARCANE_MISSILES, target);
                    }                        
                }
            }
            /*else if (utils.isAuraActive(ARCANE_POWER,Me))
            {
                WoWUnit target = utils.getTargetToAttack(40, tank);
                if (target != null)
                {
                    if (Me.Combat || (tank != null && tank.Combat))
                    {
                        target.Target();
                        if (!Me.IsMoving && !Me.IsFacing(target))
                        {
                            utils.LogActivity(FACING, target.Name);
                            Me.SetFacing(target);
                        }
                        if (utils.PlayerCountBuff(ARCANE_MISSILES_PROC) > 0 && Me.IsFacing(target))
                        {
                            utils.LogActivity(ARCANE_MISSILES, target.Name);
                            return utils.Cast(ARCANE_MISSILES, target);
                        }
                    }
                }
            }*/
            return false;
        }

        private bool BotUpdate()
        {
            if (BaseBot.Equals(BotManager.Current.Name))
                return false;
            if (utils.IsBotBaseInUse("LazyRaider") || utils.IsBotBaseInUse("Tyrael"))
            {
                Logging.Write("Detected LazyRaider/tyrael:");
                Logging.Write("Disable all movements");
                Movement.DisableAllMovement = true;
                LazyRaiderBotType = true;
                RaidBotBotType = false;
                SoloBotType = false;
                PVPBotType = false;
                BaseBot = BotManager.Current.Name;
                return true;
            }

            if (utils.IsBotBaseInUse("Raid Bot"))
            {
                Logging.Write("Detected RaidBot:");
                Logging.Write("Disable all movements");
                Movement.DisableAllMovement = true;
                LazyRaiderBotType = false;
                RaidBotBotType = true;
                SoloBotType = false;
                PVPBotType = false;
                BaseBot = BotManager.Current.Name;
                return true;
            }


            if (utils.IsBotBaseInUse("BGBuddy"))
            {
                Logging.Write("Detected BGBuddy Bot:");
                Logging.Write("Enable PVP Rotation");
                Movement.DisableAllMovement = true;
                LazyRaiderBotType = false;
                RaidBotBotType = false;
                SoloBotType = false;
                PVPBotType = true;
                BaseBot = BotManager.Current.Name;
                return true;
            }

            Logging.Write("Base bot detected: " + BotManager.Current.Name);
            LazyRaiderBotType = false;
            SoloBotType = true;
            PVPBotType = false;
            RaidBotBotType = false;
            BaseBot = BotManager.Current.Name;
            return true;


        }

        private bool Defensivececk()
        {
            if (SoloBotType)
            {
                if (Me.Combat && Me.HealthPercent < 10 && !StyxWoW.Me.ActiveAuras.ContainsKey("Hypothermia") && utils.CanCast(ICE_BLOCK))
                {
                    utils.LogActivity(ICE_BLOCK, Me.Name);
                    return utils.Cast(ICE_BLOCK);
                }

                if (Me.Combat && (utils.AllAttaccableEnemyMobsInRange(12).Count() >= 1) && utils.CanCast(FROST_NOVA))
                {
                    utils.LogActivity(FROST_NOVA);
                    utils.Cast(FROST_NOVA);
                }

                if (ArcaneMageSettings.Instance.UseBlink && Me.Combat && (utils.AllAttaccableEnemyMobsInRange(5).Count() >= 1) && utils.CanCast(BLINK))
                {
                    utils.LogActivity(BLINK);
                    return utils.Cast(BLINK);
                }
                return false;

            }
            return false;
        }

        private bool CombatRotation()
        {
            extra.UseHealthstone();
            extra.UseAlchemyFlask();
            extra.WaterSpirit();
            extra.LifeSpirit();
            Defensivececk();
            extra.UseRacials();
            extra.UseTrinket1();
            extra.UseTrinket2();
            extra.UseEngineeringGloves();
            extra.UseLifeblood();
            UseCD();
            ProcWork();
            if (RecMana())
                return true;


            WoWUnit target = utils.getTargetToAttack(40, tank);
            if (target != null && !target.IsFriendly && !target.IsDead && target.Attackable)
            {              
                target.Target();
                if (!Me.IsMoving)
                {
                    //utils.LogActivity(FACING, target.Name);
                    Me.SetFacing(target);
                }

                //deep freeze
                if (ArcaneMageSettings.Instance.UseDeepFreeze && utils.CanCast(DEEP_FREEZE,target) && !target.HasAura(DEEP_FREEZE))
                {
                    utils.LogActivity(DEEP_FREEZE, target.Name);
                    return utils.Cast(DEEP_FREEZE, target);
                }

                if (PriorityBuff())
                    return true;

                if (target.Distance <= 30 && ArcaneMageSettings.Instance.UseFireBlast && utils.CanCast(FIRE_BLAST, target) &&
                    utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 10).Count() >= 2 &&
                    (utils.MyAuraTimeLeft(NETHER_TEMPEST, target) > 1500 || utils.MyAuraTimeLeft(LIVING_BOMB, target) > 1500 || utils.MyAuraTimeLeft(FROST_BOMB, target) > 1500))
                {
                    utils.LogActivity(FIRE_BLAST, target.Name);
                    return utils.Cast(FIRE_BLAST, target);
                }


                //apply  Nether Tempest and always refresh it right before the last tick;
                if (utils.CanCast(NETHER_TEMPEST, target) && (utils.MyAuraTimeLeft(NETHER_TEMPEST, target) < 2000))
                {
                    utils.LogActivity(NETHER_TEMPEST, target.Name);
                    return utils.Cast(NETHER_TEMPEST, target);
                }

                //apply  Living Bomb and refresh it right before or right after the last tick (the expiring Living Bomb will explode in both cases);
                if (utils.CanCast(LIVING_BOMB, target) && (utils.MyAuraTimeLeft(LIVING_BOMB, target) < 2000))
                {
                    utils.LogActivity(LIVING_BOMB, target.Name);
                    return utils.Cast(LIVING_BOMB, target);
                }

                //cast  Frost Bomb on cooldown.
                if (utils.CanCast(FROST_BOMB, target))
                {
                    utils.LogActivity(FROST_BOMB, target.Name);
                    return utils.Cast(FROST_BOMB, target);
                }

                //+++++++++++++++++++++++++AOE rotation start+++++++++++++++++++++++++++++++//
                if (utils.CanCast(FLAMESTRIKE) &&target.Distance <= 40 && utils.AllAttaccableEnemyMobsInRangeFromTarget(target, 15).Count() >= ArcaneMageSettings.Instance.AOECount)
                {
                    utils.LogActivity(FLAMESTRIKE, target.Name);
                    utils.Cast(FLAMESTRIKE);
                    return SpellManager.ClickRemoteLocation(target.Location);
                }


                if (utils.CanCast(ARCANE_EXPLOSION) && utils.AllAttaccableEnemyMobsInRange(15).Count() >= ArcaneMageSettings.Instance.AOECount)
                {
                    utils.LogActivity(ARCANE_EXPLOSION);
                    return utils.Cast(ARCANE_EXPLOSION);
                }

                if (ArcaneMageSettings.Instance.UseScorchInRotation && utils.CanCast(SCORCH, target)
                    && !(utils.PlayerCountBuff(ARCANE_MISSILES_PROC) > 0)
                    && Me.ManaPercent <= ArcaneMageSettings.Instance.ScorchMana
                    && utils.MyAuraTimeLeft(ARCANE_CHARGE, Me) >= 2000)
                {
                    utils.LogActivity(SCORCH, target.Name);
                    return utils.Cast(SCORCH, target);
                }


                if (!Me.IsMoving && utils.CanCast(ARCANE_BLAST, target))
                {
                    utils.LogActivity(ARCANE_BLAST, target.Name);
                    return utils.Cast(ARCANE_BLAST, target);
                }

                //+++++++++++++++++++++++DPS moving   START+++++++++++++++++++++++++++

                //PRESENCE OF MIND
                if (utils.CanCast(PRESENCE_OF_MIND) && !utils.isAuraActive(PRESENCE_OF_MIND))
                {
                    utils.LogActivity(PRESENCE_OF_MIND);
                    utils.Cast(PRESENCE_OF_MIND);
                }
                if (utils.isAuraActive(PRESENCE_OF_MIND) && utils.CanCast(ARCANE_BLAST, target))
                {
                    utils.LogActivity(ARCANE_BLAST, target.Name);
                    return utils.Cast(ARCANE_BLAST, target);
                }


                //ICE_FLOE
                if (Me.IsMoving && utils.CanCast(ICE_FLOES) && !utils.isAuraActive(ICE_FLOES))
                {
                    utils.LogActivity(ICE_FLOES);
                    utils.Cast(ICE_FLOES);
                }
                if (utils.isAuraActive(ICE_FLOES) && utils.CanCast(ARCANE_BLAST, target))
                {
                    utils.LogActivity(ARCANE_BLAST, target.Name);
                    return utils.Cast(ARCANE_BLAST, target);
                }

                if (Me.IsMoving && SpellManager.HasSpell(SCORCH))
                {
                    utils.LogActivity(SCORCH, target.Name);
                    return utils.Cast(SCORCH, target);
                }

                if (Me.IsMoving && utils.CanCast(FIRE_BLAST))
                {
                    utils.LogActivity(FIRE_BLAST, target.Name);
                    return utils.Cast(FIRE_BLAST, target);
                }

                if (Me.IsMoving && utils.CanCast(ICE_LANCE, target))
                {
                    utils.LogActivity(ICE_LANCE, target.Name);
                    return utils.Cast(ICE_LANCE, target);
                }   
                //+++++++++++++++++++++++DPS moving  END+++++++++++++++++++++++++++

                if (SoloBotType)
                {
                    movement.KingHealMove(target.Location, ArcaneMageSettings.Instance.PullDistance, true, true);
                }
            }
            /*else
            {
                Logging.Write("cant target: ");
                if (Me.CurrentTarget != null)
                {
                    Logging.Write("my currenttarget: " + Me.CurrentTarget.Name + " distance: " + Me.CurrentTarget.Distance+ "inlos:"+
                        Me.CurrentTarget.InLineOfSight.ToString());
                }
                Logging.Write("My current target is NULL!");
                if (tank != null)
                {
                    Logging.Write("tank is: " + tank.Name);
                    if (tank.CurrentTarget != null)
                        Logging.Write("tank's target is: " + tank.CurrentTarget.Name + " distance: " + tank.CurrentTarget.Distance + "inlos:" +
                        tank.CurrentTarget.InLineOfSight.ToString());
                    else
                        Logging.Write("tank's target is NULL!!!: ");
                }
                else
                    Logging.Write("tank is NULL!!");
            }*/
            return false;
        }

        //Arcane Power
        //Mirror image
        //Alter Time
        private bool UseCD()
        {
            if (Me.Combat && Me.GotTarget)
            {
                if (utils.CanCast(ARCANE_POWER) && utils.PlayerCountBuff(ARCANE_CHARGE) == 6 && ArcaneMageSettings.Instance.CDUseArcanePower == ArcaneMageSettings.CDUseType.COOLDOWN)
                {
                    utils.LogActivity(ARCANE_POWER);
                    return utils.Cast(ARCANE_POWER);
                }
                if (utils.CanCast(MIRROR_IMAGE) && ArcaneMageSettings.Instance.CDUseMirrorImage == ArcaneMageSettings.CDUseType.COOLDOWN)
                {
                    utils.LogActivity(MIRROR_IMAGE);
                    return utils.Cast(MIRROR_IMAGE);
                }
                if (utils.CanCast(ALTER_TIME) && ArcaneMageSettings.Instance.CDUseAlterTime == ArcaneMageSettings.CDUseType.COOLDOWN
                    && (utils.PlayerCountBuff(ARCANE_CHARGE) == 6 && utils.PlayerCountBuff(ARCANE_MISSILES_PROC) == 2))
                {
                    utils.LogActivity(ALTER_TIME);
                    return utils.Cast(ALTER_TIME);
                }

                if (extra.IsTargetBoss())
                {
                    if (utils.CanCast(ARCANE_POWER) && utils.PlayerCountBuff(ARCANE_CHARGE) == 6 && ArcaneMageSettings.Instance.CDUseArcanePower == ArcaneMageSettings.CDUseType.BOSS)
                    {
                        utils.LogActivity(ARCANE_POWER);
                        return utils.Cast(ARCANE_POWER);
                    }
                    if (utils.CanCast(MIRROR_IMAGE) && ArcaneMageSettings.Instance.CDUseMirrorImage == ArcaneMageSettings.CDUseType.BOSS)
                    {
                        utils.LogActivity(MIRROR_IMAGE);
                        return utils.Cast(MIRROR_IMAGE);
                    }
                    if (utils.CanCast(ALTER_TIME) && ArcaneMageSettings.Instance.CDUseAlterTime == ArcaneMageSettings.CDUseType.BOSS
                        && (utils.PlayerCountBuff(ARCANE_CHARGE) == 6 && utils.PlayerCountBuff(ARCANE_MISSILES_PROC) == 2))
                    {
                        utils.LogActivity(ALTER_TIME);
                        return utils.Cast(ALTER_TIME);
                    }

                }
            }
            return false;
        }

        private bool RecMana()
        {
            if (Me.ManaPercent < ArcaneMageSettings.Instance.UseManaGemPercent)
            {
                utils.UseBagItem(MANA_GEM);
                utils.UseBagItem(BRILLIANT_MANA_GEM);
            }

            if (!Me.IsMoving && Me.ManaPercent < ArcaneMageSettings.Instance.UseEvocationPercent)
            {
                utils.LogActivity(EVOCATION);
                return utils.Cast(EVOCATION);
            }
            return false;
        }
    }
}